package com.gemfire.onlineretailer.domain;

/**
 * All the items that the organization uses directly or indirectly to manufacture the finished goods it sells, are account for  
 * 
 * @author Binit Datta
 */

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Date;

import com.gemstone.gemfire.DataSerializable;
import com.gemstone.gemfire.DataSerializer;

public class Item implements DataSerializable{
	  private static final long serialVersionUID = 1L;
	  
	  public static final long ITEM_1 = 10000001;
	  public static final long ITEM_2 = 10000002;

	  public static final long ITEM_3 = 10000003;
	  public static final long ITEM_4 = 10000004;
	  public static final long ITEM_5 = 10000005;
	  
	  public static final String ITEM_1_CODE = "10000001";
	  public static final String ITEM_2_CODE = "10000002";

	  public static final String ITEM_3_CODE = "10000003";
	  public static final String ITEM_4_CODE = "10000004";
	  public static final String ITEM_5_CODE = "10000005";

	  private long itemId;
	  private String itemCode;
	  private int itemType;
	  private String itemName;
	  private String itemDescription;
	  private long reorderLevel;
	  private int unitOfMeasurement;
	  private long minLevel;
	  private long maxLevel;
	  private Date sellDate;
	  private float sellPrice;
	  
	  
	  
	  
	public long getMaxLevel() {
		return maxLevel;
	}
	public void setMaxLevel(long maxLevel) {
		this.maxLevel = maxLevel;
	}
	public Date getSellDate() {
		return sellDate;
	}
	public void setSellDate(Date sellDate) {
		this.sellDate = sellDate;
	}
	public float getSellPrice() {
		return sellPrice;
	}
	public void setSellPrice(float sellPrice) {
		this.sellPrice = sellPrice;
	}
	public long getItemId() {
		return itemId;
	}
	public void setItemId(long itemId) {
		this.itemId = itemId;
	}
	public String getItemCode() {
		return itemCode;
	}
	public void setItemCode(String itemCode) {
		this.itemCode = itemCode;
	}
	public int getItemType() {
		return itemType;
	}
	public void setItemType(int itemType) {
		this.itemType = itemType;
	}
	public String getItemName() {
		return itemName;
	}
	public void setItemName(String itemName) {
		this.itemName = itemName;
	}
	public String getItemDescription() {
		return itemDescription;
	}
	public void setItemDescription(String itemDescription) {
		this.itemDescription = itemDescription;
	}
	public long getReorderLevel() {
		return reorderLevel;
	}
	public void setReorderLevel(long reorderLevel) {
		this.reorderLevel = reorderLevel;
	}
	public int getUnitOfMeasurement() {
		return unitOfMeasurement;
	}
	public void setUnitOfMeasurement(int unitOfMeasurement) {
		this.unitOfMeasurement = unitOfMeasurement;
	}
	public long getMinLevel() {
		return minLevel;
	}
	public void setMinLevel(long minLevel) {
		this.minLevel = minLevel;
	}
	public long getMaxLevele() {
		return maxLevel;
	}
	public void setMaxLevele(long maxLevele) {
		this.maxLevel = maxLevele;
	}
	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	  
	
	public static Item createInstance(long itemId){
		
		/*
		 * Use itemId to read from DB or from other source, Hardcode for now
		 */
		
		Item item = new Item();
		
		if (itemId == ITEM_1){
			item.setItemId(itemId);
			item.setItemCode(ITEM_1_CODE);
			item.setItemType(ItemType.RAW_MATERIALS.getCode()); 
			item.setItemName("HCL");
		} 
		else if (itemId == ITEM_2){
			item.setItemId(itemId);
			item.setItemCode(ITEM_2_CODE);
			item.setItemType(ItemType.ELECTRICAL.getCode()); 
			item.setItemName("Wire");
		} 
		else if (itemId == ITEM_3){
			item.setItemId(itemId);
			item.setItemCode(ITEM_3_CODE);
			item.setItemType(ItemType.BUILDING_MATERIALS.getCode()); 
			item.setItemName("Bricks");
		} 
		else if (itemId == ITEM_4){
			item.setItemId(itemId);
			item.setItemCode(ITEM_4_CODE);
			item.setItemType(ItemType.PACKAGING_MATERIALS.getCode()); 
			item.setItemName("Packaging Box");
		}
		else {
			item.setItemId(itemId);
			item.setItemCode(ITEM_5_CODE);
			item.setItemType(ItemType.FINISHED_GOODS.getCode()); 
			item.setItemName("Tablet");
			} 
		
		return item;
		
	}

	 @Override
	  public String toString() {
	    
		 StringBuffer buff = new StringBuffer();
		 
		 buff.append("Item Code :"+itemCode);
		 buff.append("Item Name :"+itemName);
		 buff.append("Item Type :"+itemType);
		 buff.append("Item Desc :"+itemDescription);
		 buff.append("Item ROL :"+reorderLevel);
		 buff.append("Item UOM :"+unitOfMeasurement);
		 buff.append("Item Name :"+itemName);
		 buff.append("Item Name :"+itemName);
		 buff.append("Item Name :"+itemName);
		 buff.append("Item Name :"+itemName);

		 return buff.toString();
		 
	  }
	@Override
	public void fromData(DataInput in) throws IOException,
			ClassNotFoundException {
		this.itemId = in.readInt();
		this.itemCode = in.readUTF();
		this.itemType = in.readInt();
		this.itemName = in.readUTF();
		this.itemDescription = in.readUTF();
		this.reorderLevel = in.readLong();
		this.unitOfMeasurement = in.readInt();
		this.minLevel = in.readLong();
		this.minLevel = in.readLong();
		this.sellDate = DataSerializer.readDate(in);
		this.sellPrice = in.readFloat();
		
	}
	@Override
	public void toData(DataOutput out) throws IOException {
	
		  out.writeLong(this.itemId);
		  out.writeUTF(this.itemCode);
		  out.writeInt(this.itemType);
		  out.writeUTF(this.itemName);
		  out.writeUTF(this.itemDescription);
		  out.writeLong(this.reorderLevel);
		  out.writeInt(this.unitOfMeasurement);
		  out.writeLong(this.minLevel);
		  out.writeLong(this.maxLevel);
		  DataSerializer.writeDate(this.sellDate, out);
		  out.writeFloat(this.sellPrice);
	}

}
